package com.liuyucheng.tools.autotimer;

import javax.swing.*;
import java.awt.*;

/**
 * Hello world!
 */
public class App {
    public static void main(String[] args) throws Exception{
        try {
            String osName = System.getProperty("os.name");
            for (UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
                if ("Mac OS X".equals(info.getName()) && osName.contains("Mac")) {
                    UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
                if ("Windows".equals(info.getName()) && osName.contains("Windows")) {
                    UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }


        //主窗口
        JFrame frame = new JFrame("自动同步时间工具");
        frame.setVisible(true);
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.setSize(1000,300);
        frame.setResizable(false);
        frame.setLocationRelativeTo(null);

        //主面板
        JPanel rootPanel = new JPanel();
        frame.setContentPane(rootPanel);
        rootPanel.setLayout(null);

        //同步按钮
        JButton buttonStart = new JButton("同步时间");
        buttonStart.setBounds(0,0,200,50);
        buttonStart.setFont(new Font("微软雅黑",Font.PLAIN,18));
        rootPanel.add(buttonStart);

        JLabel label1 = new JLabel("正在运行中...");
        label1.setVerticalTextPosition(JLabel.CENTER);
        label1.setHorizontalTextPosition(JLabel.CENTER);
        label1.setHorizontalAlignment(JLabel.CENTER);
        label1.setFont(new Font("微软雅黑",Font.PLAIN,20));
        label1.setBounds(200,0,300,50);
        rootPanel.add(label1);


        //绑定事件
        buttonStart.addActionListener(e -> {
            String time = UpdateLocalTimeUtil.synchronizeTime();
            String msg = "系统时间已经更新为："+time;
            label1.setText(msg);
        });
    }
}
